<template>
  <el-card>
    <template #header>
      <div class="card-header">
        <el-button type="primary" icon="Plus" @click="addTrademark" v-has="`btn.Trademark.add`">添加品牌</el-button>
      </div>
    </template>
    <el-table :data="trademarkArr">
      <el-table-column label="序号" width="80px" align="center" type="index"></el-table-column>
      <!-- table-column:默认展示数据用div -->
      <el-table-column label="品牌名称" prop="tmName"></el-table-column>
      <el-table-column label="品牌LOGO">
        <template #default="{ row }">
          <img :src="row.logoUrl" style="width: 100px; height: 100px" />
        </template>
      </el-table-column>
      <el-table-column label="品牌操作">
        <template #default="{ row }">
          <el-button type="primary" size="small" icon="Edit" @click="updateTrademark(row)"></el-button>
          <el-popconfirm
            :title="`您确定要删除${row.tmName}?`"
            width="250px"
            icon="Delete"
            @confirm="removeTradeMark(row.id)"
          >
            <template #reference>
              <el-button type="primary" size="small" icon="Delete"></el-button>
            </template>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 15px"
      v-model:current-page="pageNo"
      v-model:page-size="pageSize"
      :page-sizes="[3, 5, 7, 9]"
      :background="true"
      layout="total, sizes, prev, pager, next, ->,jumper"
      :total="total"
      @size-change="sizeChange"
      @current-change="getHasTrademark"
    />
  </el-card>
  <tableModal ref="tableLogRef" :title="'新增'"></tableModal>
</template>

<script setup lang="ts">
import tableModal from './tableModal.vue'
import { onMounted, ref } from 'vue'
import { reqHasTrademark } from '@/api/product/trademark'
const pageNo = ref<number>(1)
const pageSize = ref<number>(3)
const total = ref<number>(0)
const trademarkArr = ref<any[]>([])
const tableLogRef = ref(null)
onMounted(() => {
  getHasTrademark()
})
const sizeChange = () => {
  //当前每一页的数据量发生变化的时候，当前页码归1
  getHasTrademark()
}
const getHasTrademark = async (pager = 1) => {
  console.log(pager)
  pageNo.value = pager
  const result = await reqHasTrademark(pageNo.value, pageSize.value)
  trademarkArr.value = result.data.records
  total.value = result.data.total
}

const addTrademark = (row: any) => {
  console.log(row)
  tableLogRef.value.open()
}
const updateTrademark = (row: any) => {
  console.log(row)
}
const removeTradeMark = (id: number) => {
  console.log(id)
}
</script>

<style scoped></style>
